<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>请求页面</title>
    <style>
        #iframe {
            border: 2px solid greenyellow;
            width: 500px;
            height: 200px;
            margin: 0 auto;
            text-align: center;
        }
        #father {
            border: 2px solid darkturquoise;
            width: 500px;
            height: 200px;
            margin-bottom: 20px;
            display: block;
        }
    </style>
</head>
<body>
<div id="father">
    <h2 style="text-align: center;">document.domain跨域demo</h2>
    <p>hello world</p>
</div>
<iframe src="http://b.xuhaodong.cn/b.html" id="iframe" onload="test()"></iframe>
<script>
    var p = document.getElementsByTagName('p')[0];
    document.domain = 'xuhaodong.cn';//设置成主域
    function test(){
        var win_b = document.getElementById('iframe').contentWindow;
        var data = win_b.data;
        alert('稍后获得来自b.xuhaodong.cn的数据');
        p.innerHTML = data;
    }
</script>
</body>
</html>